﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<input type="button" value="测试pako解压java传过来的压缩字符串" onclick="pakoTest();"/>
<div>#####################我是分割线#######################</div>
<div id="d2" style="width: 600px; height: 300px; background-color: aquamarine;"></div>
</body>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.base64.js"></script>
<script src="js/pako.min.js"></script>
<script>// 解压
function unzip(key) {
    var charData = [];
    var keyArray = key.split('');
    for (var i = 0; i < keyArray.length; i++) {
        var item = keyArray[i];
        charData.push(item.charCodeAt(0));
    }
    var data = pako.inflate(charData);
    key = String.fromCharCode.apply(null, data);
    return decodeURIComponent($.base64.decode(key));
}

// 压缩
function zip(str) {
    let clientData = pako.deflate(str);
    clientData = clientData.toString()
    return clientData;
}

function pakoTest() {

    var desc = "我是张三 **@*￥）*￥*）@#*#*@+—— ~kdfkda55d4 fd";

    var reqUrl = 'http://localhost:8080/zip/test?data=' + zip(desc);

   // reqUrl = "http://localhost:18087/wo/detail?orderId=1512265403018629121";

    $.ajax({
        url: reqUrl,
        type: "GET",
        success: function (data) {
            console.log("接受 server 压缩原文:", data);
            var rst = unzip(data);

            $('#d2').html(rst);
        },
        error: function (rtn) {
            alert("失败了");
        }
    });
}


</script>

</html>